Prev Next |
GetItemDefinition returns the requested item’s ItemDefinition.
public override ItemDefinition GetItemDefinition(
ID itemID,
CallContext context
)
Sitecore calls this method to retrieve basic information about an item from the physical storage. Sitecore passes the desired item’s ID and expects the item’s ItemDefinition in return. The ItemDefinition includes the item’s ID, name, corresponding Template ID, and corresponding Master ID (null if the item was not created via a Master). The method must return an instance of the ItemDefinition class or null, if the requested item does not exist.
The following example shows the GetItemDefinition method from the Hello World example.
public override ItemDefinition GetItemDefinition(ID itemID, CallContext
context)
{
// Ignore the provided item ID. This method always returns
// a single, hard coded item. A more useful data provider
// would use the ID to map to a data source key and retrieve
// the item using this key.
// Hard code the item’s name
string itemName = "Hello World";
// Hard code the item’s template. Must provide the same
// template ID as is created in the GetTemplates method
ID templateID = new
ID("{ABD9F13F-DFAC-4ED9-8C23-E0A9C5BB19C9}");
// Hard code the item’s master. Null indicates that the
// item was not created via a master.
ID masterID = ID.Null;
// Create and return an ItemDefinition using the provided
// Item ID and hard coded name, template ID, and master ID.
return new ItemDefinition(itemID, itemName, templateID, masterID);
}
Note that a true implementation would most likely use the IDTable to locate the appropriate data source key based on the provided ID, then use the key to locate the item from the data source. The developer would set the item name based on appropriate information in the retrieve item.
The method must also return the Template that the item inherits from and the Master used to create the item, if any. The data provider may map this information to each item in whatever way it sees fit. For example, the Template ID could be included in the IDTable as custom data.
Prev Next